package com.sunda.spmsweb.usercontroller;


import com.sunda.spmscommon.ResponseResult;
import com.sunda.spmsuser.service.ISpmsPermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * spms权限表 前端控制器
 * </p>
 *
 * @author Wayne
 * @since 2021-01-25
 */
@RestController
@RequestMapping("/spmsPerm")
@Api(tags = "系统权限信息表", description = "系统权限信息表")
public class SpmsPermissionController {

    @Autowired
    ISpmsPermissionService iSpmsPermissionService;

    @RequestMapping("/getAllPerm")
    @ApiOperation(value = "获取全部菜单权限信息", notes = "获取全部菜单权限信息", httpMethod = "GET")
    public ResponseResult getAllPerm(){
        try {
            return ResponseResult.success().add("spmsPermissionList", iSpmsPermissionService.getAllPerm());
        }catch (Exception e){
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }

    /**
    @RequestMapping("/createSpmsPerm")
    @ApiOperation(value = "新增/更新权限信息", notes = "新增/更新权限信息。\n" +
            "permissionId 不为空，数据存在则更新权限信息数据；不存在则更新权限数据；\n" +
            "{\n" +
            "\t\"redirect\": null,\n" +
            "\t\"permissionId\": \"900101\",\n" +
            "\t\"menuEnName\": \"Material search\",\n" +
            "\t\"icon\": null,\n" +
            "\t\"description\": null,\n" +
            "\t\"updateUser\": \"\",\n" +
            "\t\"menuName\": \"物料搜索\",\n" +
            "\t\"componentUrl\": null,\n" +
            "\t\"isLeaf\": 0,\n" +
            "\t\"parentId\": null,\n" +
            "\t\"url\": \"/search\",\n" +
            "\t\"sortNo\": null,\n" +
            "\t\"permsType\": \"0\",\n" +
            "\t\"menuType\": null,\n" +
            "\t\"perms\": null,\n" +
            "\t\"createUser\": \"999947\",\n" +
            "\t\"componentName\": null,\n" +
            "\t\"isRoute\": 1,\n" +
            "\t\"alwaysShow\": null\n" +
            "}", httpMethod = "POST")
    public ResponseResult createSpmsPerm(@RequestBody JSONObject jsonObject){
        try {
            return iSpmsPermissionService.createSpmsPerm(jsonObject);
        }catch (Exception e){
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }
     ***/

    @RequestMapping("/getPermsByUserId")
    @ApiOperation(value = "获取用户权限信息", notes = "获取用户权限信息。", httpMethod = "POST")
    public ResponseResult getPermsByUserId(String userId){
        try {
            return ResponseResult.success().add("userPerms", iSpmsPermissionService.getPermsByUserId(userId));
        }catch (Exception e){
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }


}
